package com.empresa.rhtutorial.controller.jsf.unidadeorganizacional;

import java.util.Collections;
import java.util.List;

import javax.enterprise.inject.Produces;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.inject.Named;

import com.empresa.rhtutorial.commons.AppBaseContextVO;
import com.empresa.rhtutorial.controller.jsf.AppMB;
import com.empresa.rhtutorial.entity.Municipio;
import com.empresa.rhtutorial.entity.MunicipioEntity;
import com.empresa.rhtutorial.entity.UfEntity;
import com.empresa.rhtutorial.entity.UnidadeOrganizacionalEntity;
import com.powerlogic.jcompany.commons.annotation.PlcUriIoC;
import com.powerlogic.jcompany.commons.config.stereotypes.SPlcMB;
import com.powerlogic.jcompany.config.aggregation.PlcConfigAggregation;
import com.powerlogic.jcompany.config.collaboration.FormPattern;
import com.powerlogic.jcompany.config.collaboration.PlcConfigBehavior;
import com.powerlogic.jcompany.config.collaboration.PlcConfigForm;
import com.powerlogic.jcompany.config.collaboration.PlcConfigFormLayout;
import com.powerlogic.jcompany.config.collaboration.PlcConfigNestedCombo;
import com.powerlogic.jcompany.controller.jsf.annotations.PlcHandleException;

@PlcConfigAggregation(
		entity = com.empresa.rhtutorial.entity.UnidadeOrganizacionalEntity.class,
		components = {@com.powerlogic.jcompany.config.aggregation.PlcConfigComponent(clazz=com.empresa.rhtutorial.entity.Endereco.class, property="endereco", separate=true)}
	)
@PlcConfigForm (
	formPattern=FormPattern.Man,
	formLayout = @PlcConfigFormLayout(dirBase="/WEB-INF/fcls/unidadeOrganizacional"),
	behavior = @PlcConfigBehavior(useTreeView=true),
	nestedCombo = @PlcConfigNestedCombo(origemProp="endereco.uf",destinyProp="endereco.municipio")
)
/**
 * Classe de Controle gerada pelo assistente
 */
@SPlcMB
@PlcUriIoC("unidadeorganizacional")
@PlcHandleException
public class UnidadeOrganizacionalMB extends AppMB  {

	private static final long serialVersionUID = 1L;
	private transient List<MunicipioEntity> municipioSelect;
	
	/**
	* Entidade da ação injetado pela CDI
	*/
	@Produces  @Named("unidadeorganizacional")
	public UnidadeOrganizacionalEntity createEntityPlc() {
        if (this.entityPlc==null) {
              this.entityPlc = new UnidadeOrganizacionalEntity();
              this.newEntity();
        }
        return (UnidadeOrganizacionalEntity)this.entityPlc;     	
	}
	

	public void valueChangeSelect(ValueChangeEvent event) {
		System.out.println("------------------------------------> ");
		AppBaseContextVO context = new AppBaseContextVO();
		context.setApiQuerySel("querySel");
		event.getComponent().processUpdates(FacesContext.getCurrentInstance());
		Object newValue = event.getNewValue();
		System.out.println("--> " + newValue);
		if (newValue == null) {
			municipioSelect = Collections.emptyList();
		} else if (newValue instanceof Municipio) {
			UfEntity motivoMovimentoArg = new UfEntity();
//			motivoMovimentoArg.setUsuarioUltAlteracao(usuarioUltAlteracao)((Municipio) newValue);
//			context.setEntityClassPlc(motivoMovimentoArg.getClass());
//			municipioSelect = findAll(motivoMovimentoArg, context);
		}
		System.out.println("------------------------------------> ");
	}
		
}
